const path = require('path')

// 排除 elementUI xlsx  和 vue
// const externals = {
//   vue: 'Vue',
//   'element-ui': 'ELEMENT',
//   xlsx: 'XLSX',
//   echarts: 'echarts',
//   'cos-js-sdk-v5': 'COS',
//   'highligth.js': 'hljs',
//   'video.js': 'Video'
// }
// const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const isProduction = process.env.NODE_ENV === 'production'
console.log(process.env.NODE_ENV)
let externals = {}
const cdns = {
  css: ['https://unpkg.com/element-ui/lib/theme-chalk/index.css'],
  js: []
}
if (isProduction) {
  externals = {
    vue: 'Vue',
    'element-ui': 'ELEMENT',
    xlsx: 'XLSX',
    echarts: 'echarts',
    'cos-js-sdk-v5': 'COS',
    'highlight.js': 'hljs',
    'video.js': 'Video'
    // 'vue-quill-editor': 'vue-quill-editor'
  }
  cdns.js = [
    'https://unpkg.com/vue/dist/vue.js', // vuejs
    'https://unpkg.com/element-ui/lib/index.js', // element
    'https://cdn.jsdelivr.net/npm/xlsx@0.16.6/dist/xlsx.full.min.js', // xlsx 相关
    'https://cdn.jsdelivr.net/npm/xlsx@0.16.6/dist/jszip.min.js', // xlsx 相关
    'https://cdn.jsdelivr.net/npm/echarts@4.6.0/dist/echarts.min.js',
    'https://cdn.jsdelivr.net/npm/cos-js-sdk-v5/dist/cos-js-sdk-v5.min.js',
    'https://cdn.bootcdn.net/ajax/libs/highlight.js/11.3.1/highlight.min.js'
    // 'https://cdn.staticfile.org/quill/1.3.6/quill.js'

  ]
  cdns.css = [
    'https://unpkg.com/element-ui/lib/theme-chalk/index.css',
    'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/styles/default.min.css',
    'https://cdn.bootcdn.net/ajax/libs/video.js/6.6.2/alt/video-js-cdn.css'
    // 'https://cdn.staticfile.org/quill/1.3.6/quill.snow.css',
    // 'https://cdn.staticfile.org/quill/1.3.6/quill.core.css',
    // 'https://cdn.staticfile.org/quill/1.3.6/quill.bubble.css'
  ]
}

module.exports = {
  lintOnSave: false,
  chainWebpack: config => {
    const svgRule = config.module.rule('svg')
    svgRule.uses.clear()
    svgRule
      .test(/.svg$/)
      .include.add(path.resolve(__dirname, './src/icons/svg'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
    const fileRule = config.module.rule('file')
    fileRule.uses.clear()
    fileRule
      .test(/.svg$/)
      .exclude.add(path.resolve(__dirname, './src/icons/svg'))
      .end()
      .use('file-loader')
      .loader('file-loader')

    config.plugin('html').tap(args => {
      args[0].cdn = cdns
      return args
    })
  },
  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.

    // 排除 elementUI xlsx  和 vue
    externals
  }
  // configureWebpack: config => {
  //   return {
  //     externals,
  //     plugins: [
  //       // 打包环境去掉console.log
  //       new UglifyJsPlugin({
  //         uglifyOptions: {
  //           compress: {
  //             warnings: false,
  //             drop_console: true, // 注释console
  //             drop_debugger: true, // 注释debugger
  //             pure_funcs: ['console.log'] // 移除console.log
  //           }
  //         }
  //       })
  //     ]
  //   }
  // }
}
